import { ICrazy } from "./interface";
import * as serice from "@/service";
const crazy: ICrazy = {
  namespaced: true,
  state: {
    crazyNav: [],
    craztList: [],
  },
  actions: {
    async getNav({ commit }) {
      const result = await serice.fetchNavlist();
      const action = {
        type: "GET_NAV",
        payload: result?.data,
      };
      commit(action);
    },
    async getlist({ commit }, { params }) {
      const result = await serice.fetchCrazylist(params.type, params.cId);
      const action = {
        type: "GET_LIST",
        payload: result?.data,
      };
      commit(action);
    },
  },
  mutations: {
    GET_NAV(state, action) {
      action.payload.unshift(
        {
          id: 0,
          title: "实时单",
          px: 0,
          appPic: "",
          goodNum: 0,
          smallPic: "",
        },
        {
          id: 0,
          title: "全天榜",
          px: 0,
          appPic: "",
          goodNum: 0,
          smallPic: "",
        }
      );

      state.crazyNav = action.payload;
    },
    GET_LIST(state, action) {
      state.craztList = action.payload;
    },
  },
};
export default crazy;
